<html>
<head><meta charset="utf-8"><title>MIR librarification compiler-team#233 · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html">MIR librarification compiler-team#233</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="183943342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/183943342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#183943342">(Dec 20 2019 at 15:10)</a>:</h4>
<blockquote>
<p>(since MIR kind of needs a definition of types)</p>
</blockquote>
<p>I have thought a few times about makeing MIR generic over the type type</p>



<a name="183943395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/183943395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#183943395">(Dec 20 2019 at 15:10)</a>:</h4>
<p>yes that is "type type" :D</p>



<a name="183943410"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/183943410" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#183943410">(Dec 20 2019 at 15:10)</a>:</h4>
<p>then we can pull it out into a separate crate</p>



<a name="183943427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/183943427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#183943427">(Dec 20 2019 at 15:10)</a>:</h4>
<p>and rustc just instantiates it with <code>Ty&lt;'tcx&gt;</code></p>



<a name="183943434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/183943434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#183943434">(Dec 20 2019 at 15:10)</a>:</h4>
<p>just like we do it with <code>TyLayout</code> right now</p>



<a name="183948720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/183948720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#183948720">(Dec 20 2019 at 16:07)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> chalk-engine does this</p>



<a name="183948781"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/183948781" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#183948781">(Dec 20 2019 at 16:08)</a>:</h4>
<p>it just has a notion of "generic argument" (which chalk currently calls <code>Parameter</code>)</p>



<a name="183948798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/183948798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#183948798">(Dec 20 2019 at 16:08)</a>:</h4>
<p>but the chalk-ir crate is sort of in the middle, and probably appropriate for MIR</p>



<a name="183948821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/183948821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#183948821">(Dec 20 2019 at 16:08)</a>:</h4>
<p>i.e., it lets you have a real notion of what a type is, while still leaving the details abstracted via the <code>TypeFamily</code> trait</p>



<a name="183948846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/183948846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#183948846">(Dec 20 2019 at 16:09)</a>:</h4>
<p>(and maybe eventually it makes sense for chalk-engine to be just using chalk-ir directly; originally I thought that rustc would directly use chalk-engine, but that's not the current goal)</p>



<a name="183950228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/183950228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#183950228">(Dec 20 2019 at 16:24)</a>:</h4>
<p>I'll look at chalk engine and chalk IR! Thanks</p>



<a name="184103808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/184103808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#184103808">(Dec 23 2019 at 13:23)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> with respect to <a href="https://github.com/rust-lang/compiler-team/issues/233" target="_blank" title="https://github.com/rust-lang/compiler-team/issues/233">compiler-team#233</a> -- I have a few questions:</p>
<ul>
<li>Do you intend to move more than just a few random data-structures?</li>
<li>Can we discuss the eventual scope of what could be extracted?</li>
</ul>
<p>In particular, I think it would be nice if we could have a library that</p>
<ul>
<li>defines the entire MIR (modulo types)</li>
<li>implements transformations and optimizations against it</li>
</ul>
<p>that was independently testable and embeddable from rustc.</p>
<p>In my ideal world, it might also cover lowering to LLVM IR, but I'm not sure if that's possible.</p>



<a name="184103850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/184103850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#184103850">(Dec 23 2019 at 13:23)</a>:</h4>
<p>I want to move the entire <code>MIR</code>. So a generic form of <code>mir::Body</code></p>



<a name="184103912"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/184103912" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#184103912">(Dec 23 2019 at 13:24)</a>:</h4>
<p>And yes, my original motivation was writing optimizations without tieing them to rustc</p>



<a name="184103935"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/184103935" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#184103935">(Dec 23 2019 at 13:25)</a>:</h4>
<p>well... codegen is already pretty nicely abstracted. I'm sure we can come up with someting</p>



<a name="184104059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/184104059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#184104059">(Dec 23 2019 at 13:26)</a>:</h4>
<p>Potentially we can even make mir interpretation generic enough so that we can start using it without rustc</p>



<a name="184104458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/184104458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#184104458">(Dec 23 2019 at 13:34)</a>:</h4>
<p>hmm, but it's not like you can switch out <code>Ty</code> for some other notion of types that is semantically different... so it would just be another representation for the same thing?</p>



<a name="184104710"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/184104710" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#184104710">(Dec 23 2019 at 13:38)</a>:</h4>
<p>If we implement logic over this generic MIR then you give up the ability to pattern match on types in that logic</p>



<a name="184104753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/184104753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#184104753">(Dec 23 2019 at 13:39)</a>:</h4>
<p>maybe, this needs to be explored, but  my hope is that we can come up with something</p>



<a name="184104768"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/184104768" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#184104768">(Dec 23 2019 at 13:39)</a>:</h4>
<p>chalk-ir has some helper traits around types</p>



<a name="184104971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/184104971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#184104971">(Dec 23 2019 at 13:43)</a>:</h4>
<p>Well, you'd need associated pattern aliases with exhaustiveness groupings to be able to use <code>match</code> again</p>



<a name="184104999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/184104999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#184104999">(Dec 23 2019 at 13:43)</a>:</h4>
<p>otherwise you'll need to use <code>.is_foobar()</code> and <code>.as_foobar()</code> and largely give up exhaustive matches</p>



<a name="184105073"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/184105073" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#184105073">(Dec 23 2019 at 13:44)</a>:</h4>
<p>(which feels like it would make a part of the compiler, that needs to be especially robust, more brittle)</p>



<a name="184105082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/184105082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#184105082">(Dec 23 2019 at 13:44)</a>:</h4>
<p>I don't think we exhaustively match <code>Ty</code> a lot</p>



<a name="184105138"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/184105138" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#184105138">(Dec 23 2019 at 13:45)</a>:</h4>
<p>There are many many things we can move without making stuff less robust in anyone's metric</p>



<a name="184105201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/184105201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#184105201">(Dec 23 2019 at 13:46)</a>:</h4>
<p>I feel like we should have this discussion once we have concrete things that are weird to move</p>



<a name="184105247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/184105247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#184105247">(Dec 23 2019 at 13:47)</a>:</h4>
<p>just making things more generic is not a goal in itself, so when we hit something that requires weird trait bounds with weird APIs then we should definitely be careful</p>



<a name="184116553"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/184116553" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#184116553">(Dec 23 2019 at 16:46)</a>:</h4>
<blockquote>
<p>hmm, but it's not like you can switch out <code>Ty</code> for some other notion of types that is semantically different... so it would just be another representation for the same thing?</p>
</blockquote>
<p>I was expecting to parameterize it eventually in the style of chalk-ir, which means that yes it's really mostly about the representation. chalk-ir in particular does permit matching (because the generic notion can convert itself to a <code>TyData</code>)</p>



<a name="184116646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/184116646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#184116646">(Dec 23 2019 at 16:48)</a>:</h4>
<p>However, I'm not sure if that's the best approach -- I guess it would be worth looking at how much different optimizations and things that operate over MIR care about Rust types (and which aspects they care about)</p>



<a name="184121248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/184121248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#184121248">(Dec 23 2019 at 17:59)</a>:</h4>
<blockquote>
<p>chalk-ir in particular does permit matching (because the generic notion can convert itself to a TyData)</p>
</blockquote>
<p>So it's sort of tag-less final + a conversion to an initial repr... sounds possibly expensive though <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span></p>



<a name="184432517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/184432517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#184432517">(Dec 29 2019 at 19:00)</a>:</h4>
<p>You also have to deal with accessing <code>TyCtxt</code> which also adds some complexity.</p>
<p>I'd like a <code>rustc_mir_types</code> crate (basically just <code>rustc::mir</code>) and have <code>rustc_mir</code> depend on it. Though that is mostly for compile time reasons. <code>rustc_mir</code> should be split up too, but that shouldn't be too hard. We could start with that and let <code>rustc_mir</code>still use <code>rustc</code> and the concrete <code>Ty</code> type.</p>



<a name="184433368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/184433368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#184433368">(Dec 29 2019 at 19:26)</a>:</h4>
<p>We can have matching by defining a generic <code>enum TyKind&lt;T&gt;</code> where <code>T</code> is the concrete <code>Ty&lt;'tcx&gt;</code>. That should have no performance impact.</p>



<a name="184433444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/MIR%20librarification%20compiler-team%23233/near/184433444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/MIR.20librarification.20compiler-team.23233.html#184433444">(Dec 29 2019 at 19:29)</a>:</h4>
<p>Having an specific <code>TyKind</code> for Mir which doesn't expose variants which can't occur in Mir could be handy.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>